package com.cloudsigns.factorymanager2.produce.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.bean.WorkPartOrderBean;
import com.cloudsigns.factorymanager2.produce.iview.IProductOrderAssignView;
import com.cloudsigns.factorymanager2.produce.model.IProductOrderAssignModel;
import com.cloudsigns.factorymanager2.produce.model.ProductOrderAssignModel;

public class ProductOrderAssignPresenter {
    private IProductOrderAssignView view;
    private IProductOrderAssignModel model;
    private Handler handler = new Handler();

    public ProductOrderAssignPresenter(IProductOrderAssignView view) {
        this.view = view;
        this.model = new ProductOrderAssignModel();
    }

    public void productOrderAssign() {
        model.getProductOrderAssign(view.getAmount(), view.getAssignReceiveAccountId(), view.getOrderId(), view.getProductId(), view.getWorkPartId(), new ProductOrderAssignModel.OnProductOrderAssignListener() {
            @Override
            public void successed(final WorkPartOrderBean workPartOrderBean) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getProductOrderAssignSuccessed(workPartOrderBean);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getProductOrderAssignFailed(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
